/*
 * 易族智汇（北京）科技有限公司 版权所有。
 * 未经许可，您不得使用此文件。
 * 官方地址：www.javamall.com.cn
 */
package com.enation.app.javashop.core.client.fallback.trade;

import com.enation.app.javashop.core.client.feignimpl.trade.OrderClientFeignImpl;
import com.enation.app.javashop.core.handler.BaseFallbackFactory;
import com.enation.app.javashop.model.security.ScanModuleDTO;
import com.enation.app.javashop.model.security.ScanResult;
import com.enation.app.javashop.model.trade.cart.dos.OrderPermission;
import com.enation.app.javashop.model.trade.order.dos.OrderDO;
import com.enation.app.javashop.model.trade.order.dos.OrderItemsDO;
import com.enation.app.javashop.model.trade.order.dto.OrderDetailDTO;
import com.enation.app.javashop.model.trade.order.enums.CommentStatusEnum;
import com.enation.app.javashop.model.trade.order.enums.OrderStatusEnum;
import com.enation.app.javashop.model.trade.order.vo.DeliveryVO;
import com.enation.app.javashop.model.trade.order.vo.OrderDetailVO;
import com.enation.app.javashop.model.trade.order.vo.OrderStatusNumVO;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @author fk
 * @version v2.0
 * @Description: 订单client断路器
 * @date 2018/9/27 14:40
 * @since v7.0.0
 */
@Component
public class OrderClientFallbackFactory extends BaseFallbackFactory<OrderClientFeignImpl> implements FallbackFactory {


    @Override
    protected OrderClientFeignImpl fallback() {
        return new OrderClientFallback();
    }

    /**
     * @author fk
     * @version v2.0
     * @Description: 订单client断路器
     * @date 2018/9/27 14:40
     * @since v7.0.0
     */
    @Component
    public static class OrderClientFallback implements OrderClientFeignImpl {

        protected final Log logger = LogFactory.getLog(this.getClass());

        @Override
        public OrderDetailDTO getModel(String orderSn) {

            this.logger.error("交易服务异常，获取某订单信息异常");

            return null;
        }

        @Override
        public void updateOrderCommentStatus(String orderSn, String statusEnum) {

            this.logger.error("交易服务异常，更新订单的评论状态异常");

        }

        @Override
        public List<OrderDetailDTO> getOrderByTradeSn(String tradeSn) {

            this.logger.error("交易服务异常，查询某交易下的订单异常");

            return null;
        }


        @Override
        public Integer getOrderNumByMemberID(Long memberId) {

            this.logger.error("交易服务异常，获取某会员订单数量异常");

            return null;
        }

        @Override
        public Integer getOrderCommentNumByMemberID(Long memberId, String commentStatus) {

            this.logger.error("交易服务异常，获取某会员某评论状态下的数量异常");

            return null;
        }

        @Override
        public OrderStatusNumVO getOrderStatusNum(Long memberId, Long sellerId) {

            this.logger.error("交易服务异常，获取某会员或者某商家的各个订单下的数量异常");

            return null;
        }

        @Override
        public boolean updateOrderStatus(String sn, OrderStatusEnum orderStatus) {
            return false;
        }

        @Override
        public boolean updateTradeStatus(String sn, OrderStatusEnum orderStatus) {
            return false;
        }

        @Override
        public void addOrderItemRefundPrice(OrderDO orderDO) {
            this.logger.error("交易服务异常，添加退款价格");
        }

        @Override
        public void updateItemsCommentStatus(String orderSn, Long goodsId, CommentStatusEnum commentStatus) {

        }

        @Override
        public List<OrderItemsDO> orderItems(String orderSn) {

            this.logger.error("交易服务异常，获取订单项异常");

            return new ArrayList<>();
        }

        @Override
        public OrderDO getOrder(String orderSn) {

            this.logger.error("交易服务异常，获取订单Do异常，ordersn"+orderSn);
            return new OrderDO();
        }

        @Override
        public void ship(DeliveryVO deliveryVO, OrderPermission permission) {

            this.logger.error("交易服务异常，收货异常");
        }

        @Override
        public List<OrderDO> listOrderByGoods(Long goodsId, Long memberId, Integer month) {
            this.logger.error("listOrderByGoods异常");

            return new List<OrderDO>() {
                @Override
                public int size() {
                    return 0;
                }

                @Override
                public boolean isEmpty() {
                    return false;
                }

                @Override
                public boolean contains(Object o) {
                    return false;
                }

                @Override
                public Iterator<OrderDO> iterator() {
                    return null;
                }

                @Override
                public Object[] toArray() {
                    return new Object[0];
                }

                @Override
                public <T> T[] toArray(T[] a) {
                    return null;
                }

                @Override
                public boolean add(OrderDO orderDO) {
                    return false;
                }

                @Override
                public boolean remove(Object o) {
                    return false;
                }

                @Override
                public boolean containsAll(Collection<?> c) {
                    return false;
                }

                @Override
                public boolean addAll(Collection<? extends OrderDO> c) {
                    return false;
                }

                @Override
                public boolean addAll(int index, Collection<? extends OrderDO> c) {
                    return false;
                }

                @Override
                public boolean removeAll(Collection<?> c) {
                    return false;
                }

                @Override
                public boolean retainAll(Collection<?> c) {
                    return false;
                }

                @Override
                public void clear() {

                }

                @Override
                public OrderDO get(int index) {
                    return null;
                }

                @Override
                public OrderDO set(int index, OrderDO element) {
                    return null;
                }

                @Override
                public void add(int index, OrderDO element) {

                }

                @Override
                public OrderDO remove(int index) {
                    return null;
                }

                @Override
                public int indexOf(Object o) {
                    return 0;
                }

                @Override
                public int lastIndexOf(Object o) {
                    return 0;
                }

                @Override
                public ListIterator<OrderDO> listIterator() {
                    return null;
                }

                @Override
                public ListIterator<OrderDO> listIterator(int index) {
                    return null;
                }

                @Override
                public List<OrderDO> subList(int fromIndex, int toIndex) {
                    return null;
                }
            };
        }

        @Override
        public List<Map> getItemsPromotionTypeandNum(String orderSn) {

            this.logger.error("交易服务异常，getItemsPromotionTypeandNum异常");
            return null;
        }

        @Override
        public List<OrderDO> queryOrderList(List<String> orderSnList) {
            this.logger.error("交易服务异常，queryOrderList异常");
            return null;
        }

        @Override
        public ScanResult scanModule(ScanModuleDTO scanModuleDTO) {
            this.logger.error("交易服务异常，scanModule异常");
            return null;
        }

        @Override
        public void reSign() {
            this.logger.error("交易服务异常，reSign异常");
        }

        @Override
        public void repair(Long orderId) {
            this.logger.error("交易服务异常，repair异常");
        }


        @Override
        public OrderDetailVO getOrderVO(String orderSn) {
            this.logger.error("交易服务异常，获取订单详细异常");

            return new OrderDetailVO();
        }

        @Override
        public void payOrder(String orderSn, Double price, String returnTradeNo, String permission) {
            if (logger.isErrorEnabled()) {
                logger.error("为订单号为" + orderSn + "的订单付款发生错误");
            }

        }
    }
}
